package com.xuecheng.content.api;

import com.xuecheng.base.model.PageParams;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.base.model.Result;
import com.xuecheng.base.model.ResultUtil;
import com.xuecheng.content.model.dto.AddCourseDto;
import com.xuecheng.content.model.dto.CourseBaseInfoDto;
import com.xuecheng.content.model.dto.EditCourseDto;
import com.xuecheng.content.model.dto.QueryCourseParamsDto;
import com.xuecheng.content.model.po.CourseBase;
import com.xuecheng.content.service.impl.CourseBaseServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Mr.M
 * @version 1.0
 * @description TODO
 * @date 2023/2/11 15:44
 */
@Api(value = "课程信息管理接口",tags = "课程信息管理接口")
@Slf4j
@RestController
public class CourseBaseController {

    @Autowired
    CourseBaseServiceImpl courseBaseService;

    /**
     * 课程查询
     * @author hjh
     * @date 2023/5/6 9:57
     * @param pageParams
     * @param queryCourseParamsDto
     * @return PageResult<CourseBase>
     */

    @ApiOperation("课程查询接口")
    @PostMapping("/course/list")
    @ApiImplicitParams(
            value = {
                    @ApiImplicitParam(name = "PageParams",value = "分页查询参数"),
                    @ApiImplicitParam(name = "QueryCourseParamsDto",value = "查询条件dto")
            }
    )
    public PageResult<CourseBase> list(PageParams pageParams, @RequestBody(required=false) QueryCourseParamsDto queryCourseParamsDto) {
        return courseBaseService.getCourseBaseListPage(pageParams,queryCourseParamsDto);
    }

    /**
     * 添加课程信息
     * @author hjh
     * @date 2023/5/6 9:31
     * @param addCourseDto
     * @return CourseBaseInfoDto
     */

    @PostMapping("/course")
    @ApiOperation("添加课程接口")
    @ApiImplicitParam(name = "CreateCourseBaseInfoDto",value = "添加课程dto")
    public CourseBaseInfoDto CreateCourseBaseInfoDto(@RequestBody @Validated AddCourseDto addCourseDto){
        // todo 后期实现动态获取id
        Long companyId = 1232141425L;
        return courseBaseService.CreateCourseBaseInfoDto(companyId,addCourseDto);
    }

    /**
     * 通过课程id查询课程信息
     * @author hjh
     * @date 2023/5/7 19:37
     * @param courseId
     * @return CourseBaseInfoDto
     */

    @ApiOperation("通过课程id查询课程信息")
    @GetMapping("course/{courseId}")
    public CourseBaseInfoDto getCourseBaseById(@PathVariable @Validated Long courseId){
//        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        log.info("principal{}",principal);
        
        return courseBaseService.getCourseBaseInfo(courseId);
    }

    /**
     * 修改课程信息
     * @author hjh
     * @date 2023/5/7 19:36
     * @param editCourseDto
     * @return CourseBaseInfoDto
     */

    @ApiOperation("修改课程")
    @PutMapping("/course")
    @ApiImplicitParam(name = "EditCourseDto",value = "修改课程dto")
    public CourseBaseInfoDto modifyCourseBase(@RequestBody @Validated EditCourseDto editCourseDto){
        // todo 后期实现动态获取id
        Long companyId = 1232141425L;
        return courseBaseService.modifyCourseBase(companyId,editCourseDto);
    }



    @DeleteMapping("/course/{courseId}")
    @ApiOperation("通过id删除课程")
    public Result<Object> deleteCourseBase(@PathVariable Long courseId){
        courseBaseService.deleteCourseBase(courseId);
        return ResultUtil.success("删除成功");
    }
}
